﻿using MB.Orm.DB;
using MB.RuleBase.Common;
using Model;
using Public.DataAccess;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Business.Service
{
    public class BPrintOrderInfo
    {
        public List<PrintOrderInfo> GetPrintOrderInfoList(int pageIndex, int pageSize, out int total, params object[] parValues)
        {
            using (var DbScope = new OperationDatabaseScope(new OperationDatabaseContext("NewWeb")))
            {
                List<PrintOrderInfo> list = PagedDatabaseExcuteByXmlHelper.NewInstance.GetPagedObjectsByXml3<PrintOrderInfo>
                                                ("Order", "GetPrintOrderInfo", pageIndex, pageSize, out total, parValues);
                return list;
            }
        }

        public bool AddOrderInfoPrintHis(List<OrderInfo_Print_His> lstOrderInfo_Print_His)
        {
            var result = true;
            var message = string.Empty;
            var oracle = new MB.RuleBase.BulkCopy.SimulatedOracleHelper();
            var db = MB.Orm.Persistence.DatabaseHelper.CreateDatabase();
            var cn = oracle.CreateOracleConnection(db.ConnectionString);
            System.Data.Common.DbTransaction tran = null;
            try
            {
                cn.Open();
                tran = cn.BeginTransaction();

                using (MB.RuleBase.BulkCopy.IDbBulkExecute bulk = MB.RuleBase.BulkCopy.DbBulkExecuteFactory.CreateDbBulkExecute(tran))
                {
                    bulk.WriteToServer("Order", "AddOrderInfoPrintHis", lstOrderInfo_Print_His);
                }

                tran.Commit();
            }
            catch (Exception ex)
            {
                MB.Util.TraceEx.Write(ex.Message);
                tran.Rollback();
                result = false;
                message = ex.Message;
            }
            finally
            {
                if (tran != null) tran.Dispose();
                if (cn != null) cn.Close();
                if (cn != null) cn.Dispose();
            }
            return result;
        }

        public List<PrintOrderInfo> GetPrintOrderInfoList(string RationStartDate, string OrderNo, string DeliverArea, string selBatch, string CustomerPayType, string Isprint, string OrderStatus)
        {
            List<PrintOrderInfo> list = new List<PrintOrderInfo>();
            try
            {
                using (var DbScope = new OperationDatabaseScope(new OperationDatabaseContext("NewWeb")))
                {
                    list = DatabaseExcuteByXmlHelper.NewInstance.GetObjectsByXml<PrintOrderInfo>("Order", "GetOrderInfo"
                       , RationStartDate, OrderNo, DeliverArea, selBatch, CustomerPayType, Isprint, OrderStatus);
                }
            }
            catch (Exception ex)
            {
                MB.Util.TraceEx.Write(ex.Message);
            }
            return list;
        }
        public List<OrderInfoDetail> GetPrintOrderInfoDetailList(string RationStartDate, string OrderNo, string DeliverArea, string selBatch, string CustomerPayType, string Isprint, string OrderStatus)
        {
            List<OrderInfoDetail> list = new List<OrderInfoDetail>();
            try
            {
                using (var DbScope = new OperationDatabaseScope(new OperationDatabaseContext("NewWeb")))
                {
                    list = DatabaseExcuteByXmlHelper.NewInstance.GetObjectsByXml<OrderInfoDetail>("Order", "GetOrderInfoDetail"
                       , RationStartDate, OrderNo, DeliverArea, selBatch, CustomerPayType, Isprint, OrderStatus);
                }
            }
            catch (Exception ex)
            {
                MB.Util.TraceEx.Write(ex.Message);
            }
            return list;
        }




        public List<PrintOrderInfo> GetPrintDPSOrderList(int pageIndex, int pageSize, out int total, params object[] parValues)
        {
            using (var DbScope = new OperationDatabaseScope(new OperationDatabaseContext("NewWeb")))
            {
                List<PrintOrderInfo> list = PagedDatabaseExcuteByXmlHelper.NewInstance.GetPagedObjectsByXml3<PrintOrderInfo>
                                                ("Order", "GetPrintDPSOrderList", pageIndex, pageSize, out total, parValues);
                return list;
            }
        }
        public List<PrintOrderInfo> GetPrintDPSOrderList(params object[] parValues)
        {
            using (var DbScope = new OperationDatabaseScope(new OperationDatabaseContext("NewWeb")))
            {
                List<PrintOrderInfo> list = PagedDatabaseExcuteByXmlHelper.NewInstance.GetPagedObjectsByXml4<PrintOrderInfo>
                                                ("Order", "GetDPSOrderNew", parValues);
                return list;
            }
        }
        public List<OrderInfoDetail> GetPrintDPSOrderDetailList(params object[] parValues)
        {
            using (var DbScope = new OperationDatabaseScope(new OperationDatabaseContext("NewWeb")))
            {
                List<OrderInfoDetail> list = PagedDatabaseExcuteByXmlHelper.NewInstance.GetPagedObjectsByXml4<OrderInfoDetail>
                                                ("Order", "GetDPSOrderDetailNew", parValues);
                return list;
            }
        }
        public List<PrintOrderInfo> GetPrintDPSOrderList(string RationStartDate, string OrderNo, string DeliverArea, string selBatch, string OrderStatus, int orderFrom, int orderEnd)
        {
            List<PrintOrderInfo> list = new List<PrintOrderInfo>();
            try
            {
                using (var DbScope = new OperationDatabaseScope(new OperationDatabaseContext("NewWeb")))
                {
                    list = DatabaseExcuteByXmlHelper.NewInstance.GetObjectsByXml<PrintOrderInfo>("Order", "GetDPSOrder"
                       , RationStartDate, OrderNo, DeliverArea, selBatch, orderFrom, orderEnd, OrderStatus);
                }
            }
            catch (Exception ex)
            {
                MB.Util.TraceEx.Write(ex.Message);
            }
            return list;
        }
        public List<OrderInfoDetail> GetPrintDPSOrderDetailList(string RationStartDate, string OrderNo, string DeliverArea, string selBatch, string OrderStatus, int orderFrom, int orderEnd)
        {
            List<OrderInfoDetail> list = new List<OrderInfoDetail>();
            try
            {
                using (var DbScope = new OperationDatabaseScope(new OperationDatabaseContext("NewWeb")))
                {
                    list = DatabaseExcuteByXmlHelper.NewInstance.GetObjectsByXml<OrderInfoDetail>("Order", "GetDPSOrderDetail"
                       , RationStartDate, OrderNo, DeliverArea, selBatch, orderFrom, orderEnd, OrderStatus);
                }
            }
            catch (Exception ex)
            {
                MB.Util.TraceEx.Write(ex.Message);
            }
            return list;
        }

        public List<PrintOrderInfo> GetPrintDeliOrderList(int pageIndex, int pageSize, out int total, params object[] parValues)
        {
            using (var DbScope = new OperationDatabaseScope(new OperationDatabaseContext("MsSql")))
            {
                List<PrintOrderInfo> list = PagedDatabaseExcuteByXmlHelper.NewInstance.GetPagedObjectsByXml3<PrintOrderInfo>
                                                ("Order", "GetPrintDeliOrder", pageIndex, pageSize, out total, parValues);
                return list;
            }
        }
        public List<PrintOrderInfo> GetPrintDeliOrderList(string RationStartDate, string OrderNo, string DeliverArea, string selBatch, string OrderStatus, int orderFrom, int orderEnd)
        {
            List<PrintOrderInfo> list = new List<PrintOrderInfo>();
            try
            {
                using (var DbScope = new OperationDatabaseScope(new OperationDatabaseContext("MsSql")))
                {
                    list = DatabaseExcuteByXmlHelper.NewInstance.GetObjectsByXml<PrintOrderInfo>("Order", "GetDeliOrder"
                       , RationStartDate, OrderNo, DeliverArea, selBatch, orderFrom, orderEnd, OrderStatus);
                }
            }
            catch (Exception ex)
            {
                MB.Util.TraceEx.Write(ex.Message);
            }
            return list;
        }
        public List<OrderInfoDetail> GetPrintDeliOrderDetailList(string RationStartDate, string OrderNo, string DeliverArea, string selBatch, string OrderStatus, int orderFrom, int orderEnd)
        {
            List<OrderInfoDetail> list = new List<OrderInfoDetail>();
            try
            {
                using (var DbScope = new OperationDatabaseScope(new OperationDatabaseContext("MsSql")))
                {
                    list = DatabaseExcuteByXmlHelper.NewInstance.GetObjectsByXml<OrderInfoDetail>("Order", "GetDeliOrderDetail"
                       , RationStartDate, OrderNo, DeliverArea, selBatch, orderFrom, orderEnd, OrderStatus);
                }
            }
            catch (Exception ex)
            {
                MB.Util.TraceEx.Write(ex.Message);
            }
            return list;
        }

        //配送系统打印订单
        public List<PrintOrderInfo> GetPrintDeliOrderList(params object[] parValues)
        {
            List<PrintOrderInfo> list = new List<PrintOrderInfo>();
            try
            {
                using (var DbScope = new OperationDatabaseScope(new OperationDatabaseContext("MsSql")))
                {
                    list = PagedDatabaseExcuteByXmlHelper.NewInstance.GetPagedObjectsByXml4<PrintOrderInfo>("Order", "GetDeliOrderNew"
                       , parValues);
                }
            }
            catch (Exception ex)
            {
                MB.Util.TraceEx.Write(ex.Message);
            }
            return list;
        }
        //配送系统不需拆分的订单明细
        public List<OrderInfoDetail> GetPrintDeliOrderDetailList1(params object[] parValues)
        {
            List<OrderInfoDetail> list = new List<OrderInfoDetail>();
            try
            {
                using (var DbScope = new OperationDatabaseScope(new OperationDatabaseContext("MsSql")))
                {
                    list = PagedDatabaseExcuteByXmlHelper.NewInstance.GetPagedObjectsByXml4<OrderInfoDetail>("Order", "GetDeliOrderDetailNew1"
                       , parValues);
                }
            }
            catch (Exception ex)
            {
                MB.Util.TraceEx.Write(ex.Message);
            }
            return list;
        }
        //配送系统需拆分的订单明细
        public List<OrderInfoDetail> GetPrintDeliOrderDetailList2(params object[] parValues)
        {
            List<OrderInfoDetail> list = new List<OrderInfoDetail>();
            try
            {
                using (var DbScope = new OperationDatabaseScope(new OperationDatabaseContext("MsSql")))
                {
                    list = PagedDatabaseExcuteByXmlHelper.NewInstance.GetPagedObjectsByXml4<OrderInfoDetail>("Order", "GetDeliOrderDetailNew2"
                       , parValues);
                }
            }
            catch (Exception ex)
            {
                MB.Util.TraceEx.Write(ex.Message);
            }
            return list;
        }

    }
}
